package com.qk.controller;



import com.qk.commom.Result;
import com.qk.entity.Role;
import com.qk.service.RoleService;


import com.qk.commom.PageResult;
import com.qk.commom.Result;
import com.qk.entity.Dept;
import com.qk.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Slf4j
@RestController
public class RoleController {
    @Autowired
    private RoleService roleService;
    @GetMapping("/roles")
    public Result list1(String name,String label,
                       @RequestParam(defaultValue = "1") Integer page,@RequestParam(defaultValue = "10") Integer pageSize){
        log.info("查询参数：name={},label={},page={},pageSize={}",name,label,page,pageSize);
        PageResult<Role> pageResult = roleService.list1(name,label,page,pageSize);
        return Result.success(pageResult);
    }

    @PostMapping("/roles")
    public Result insert(@RequestBody Role role){
        log.info("添加角色：{}",role);
        roleService.add(role);
        return Result.success();
    }
    @DeleteMapping("roles/{id}")
    public Result deleteById(@PathVariable Integer id){
        log.info("删除角色：{}",id);
        roleService.delete(id);
        return Result.success();
    }
    @GetMapping("/roles/{id}")
    public Result findById(@PathVariable Integer id){
        log.info("根据id查询角色：{}",id);
        Role role = roleService.getById(id);
        return Result.success(role);
    }
    @PutMapping("/roles")
    public Result update1(@RequestBody Role role){
        log.info("修改角色：{}",role);
        roleService.uptate1(role);
        return Result.success();
    }
    @GetMapping("/roles/list")
    public Result getAll(){
        log.info("查询所有角色");
        List<Role> roleList = roleService.getAll();
        return Result.success(roleList);
    }

}
